

#include <iostream>
#include <string>
#include <vector>
#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>

using namespace std;
using namespace boost;


using boost::mutex;

mutex mu;
static unsigned int g = 0;

void foo() {
    while (true) {
        {
            boost::mutex::scoped_lock lock(mu);/// 锁定
            g++;
            std::cout << g << std::endl;
        } /// 解锁
    }
}

int main() {
    boost::thread t1(foo);
    boost::thread t2(foo);
    boost::thread t3(foo);
    boost::thread t4(foo);
    boost::thread t5(foo);

    t1.join();
}



